<template>
    <div class="_cb_dialog" v-if="isShow">
        <header class="_cb_dialog_header">
            <slot name="header"></slot>
            <cb-button @click="close" class="_close_btn"><i class="bi bi-x-lg"></i></cb-button>
        </header>
        <main class="_cb_dialog_content">
            <slot></slot>
        </main>
        <footer class="_cb_dialog_footer">
            <slot name="footer"></slot>
        </footer>
    </div>
</template>

<script setup>
import { propsToAttrMap } from '@vue/shared';
import { useAttrs, computed, reactive } from 'vue';

const props = defineProps(['chatData'])
const attrs = useAttrs()
let tempMask = null

const data = reactive({
    show: false,
    chat: props.chatData,
    mask: typeof attrs.mask != 'undefined' ? true : false
})
const isShow = computed(()=>{
    return data.show
})

const close = ()=>{
    data.show = false
    data.chat = {}
    
    tempMask?.remove()
    tempMask = null
}

const open = (chat)=>{
    data.show = true;
    data.chat = chat
    const mask = document.createElement('div')
    mask.setAttribute("class","_cb_dialog_mask")
    document.body.appendChild(mask)
    tempMask = mask
}

defineExpose({
  close,
  open
});

</script>

<style lang="scss">
._cb_dialog_mask{
    position:fixed;
    z-index: 30;
    top:0;
    right:0;
    left:0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.185);
}
._cb_dialog{
    position:fixed;
    cursor: auto;
    padding: 10px;
    background:$dlg-back-color;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    margin: auto;
    z-index:35;
    width:45%;
    height:80%;	
    display:flex;
	flex-direction:column;
    
    border-radius: 5px;
    border: 1px solid $bd-color-active;
    box-shadow: 8px 8px 12px $box-shadow;

    ._cb_dialog_footer,
    ._cb_dialog_header{
        position: relative;
        margin-left: -10px;
        margin-right: -10px;
        margin-top: -10px;
        line-height: 2rem;
        padding: 0 8px;
        font-weight: 600;
        font-size: .9rem;
        ._close_btn{
            position:absolute;
            right:3px;
            top:3px;
        }
    }
    ._cb_dialog_content{
        flex: 1 0 auto;
    }
    ._cb_dialog_header{
        flex: 0 0 auto;
    }
    ._cb_dialog_footer{
        flex: 0 0 auto;
    }
}
</style>